import {baseEffects, baseReducers, baseState} from "../../../../models/baseModel";
import PageHelper from "utils/pageHelper";
import * as request from "../../../../services/CommonHttpService";
import AppService from "../../../../common/AppService";

export default {
  namespace: 'bindDevice',

  state: {
    ...baseState,
  },

  reducers: {
    ...baseReducers
  },

  effects: {

    ...baseEffects,

    // 进入页面加载
    * init({payload}, {put, call}) {

      yield put({type: 'loading'});

      const {notice, patientId} = payload;

      try {
        let result = yield call(request.commonGet, getBaseUrl(), {}, {patientId: patientId}, AppService.baseUrl);

        yield put({
          type: 'list',
          payload: {
            data: PageHelper.wrapPage(result),
          }
        });
      } catch (error) {
        console.error("init", error);
        yield put({type: 'loadError'});
        !!notice && notice("error", error);
      }
    },
  }

}

function getBaseUrl() {
  return "/device";
}
